/*
'===============================================================================
'  Generated From - CSharp_EasyObject_BusinessEntity.vbgen
' 
'  ** IMPORTANT  ** 
'  How to Generate your stored procedures:
' 
'  SQL      = SQL_DAAB_StoredProcs.vbgen
'  
'  This object is 'abstract' which means you need to inherit from it to be able
'  to instantiate it.  This is very easily done. You can override properties and
'  methods in your derived class, this allows you to regenerate this class at any
'  time and not worry about overwriting custom code. 
'
'  NEVER EDIT THIS FILE.
'
'  public class YourObject :  _YourObject
'  {
'
'  }
'
'===============================================================================
*/

// Generated by MyGeneration Version # (1.3.0.3)

using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.IO;

using Microsoft.Practices.EnterpriseLibrary.Data;
using NCI.EasyObjects;

namespace CMS.DAL
{

	#region Schema

	public class AlbumImagesSchema : NCI.EasyObjects.Schema
	{
		private static ArrayList _entries;
		public static SchemaItem ImageID = new SchemaItem("ImageID", DbType.Int32, true, false, false, true, false, false);
		public static SchemaItem ImageName = new SchemaItem("ImageName", DbType.String, SchemaItemJustify.None, 250, true, false, false, false);
		public static SchemaItem AlbumID = new SchemaItem("AlbumID", DbType.Int32, false, true, false, false, false, false);

		public override ArrayList SchemaEntries
		{
			get
			{
				if (_entries == null )
				{
					_entries = new ArrayList();
					_entries.Add(AlbumImagesSchema.ImageID);
					_entries.Add(AlbumImagesSchema.ImageName);
					_entries.Add(AlbumImagesSchema.AlbumID);
				}
				return _entries;
			}
		}
		
		public static bool HasAutoKey 
		{
			get { return true;	}
		}

		public static bool HasRowID 
		{
			get { return false;	}
		}
	}
	#endregion

	public abstract class _AlbumImages : EasyObject
	{

		public _AlbumImages()
		{
			AlbumImagesSchema _schema = new AlbumImagesSchema();
			this.SchemaEntries = _schema.SchemaEntries;
			this.SchemaGlobal = "dbo";
		}
		
		public override void FlushData() 	 
		{ 	 
			this._whereClause = null; 	 
			this._aggregateClause = null; 	 
			base.FlushData(); 	 
		}
			   
		/// <summary>
		/// Loads the business object with info from the database, based on the requested primary key.
		/// </summary>
		/// <param name="ImageID"></param>
		/// <returns>A Boolean indicating success or failure of the query</returns>
		public bool LoadByPrimaryKey(int ImageID)
		{
			switch(this.DefaultCommandType)
			{
				case CommandType.StoredProcedure:
					ListDictionary parameters = new ListDictionary();

					// Add in parameters
					parameters.Add(AlbumImagesSchema.ImageID.FieldName, ImageID);

					return base.LoadFromSql(this.SchemaStoredProcedureWithSeparator + "sp_GetAlbumImages", parameters, CommandType.StoredProcedure);

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					this.Where.ImageID.Value = ImageID;
					return this.Query.Load();

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}
	
		/// <summary>
		/// Loads all records from the table.
		/// </summary>
		/// <returns>A Boolean indicating success or failure of the query</returns>
		public bool LoadAll()
		{
			switch(this.DefaultCommandType)
			{
				case CommandType.StoredProcedure:
					return base.LoadFromSql(this.SchemaStoredProcedureWithSeparator + "sp_GetAllAlbumImages", null, CommandType.StoredProcedure);

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					return this.Query.Load();

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		/// <summary>
		/// Adds a new record to the internal table.
		/// </summary>
		public override void AddNew()
		{
			base.AddNew();
			this.ApplyDefaults();
		}

		/// <summary>
		/// Apply any default values to columns
		/// </summary>
		protected override void ApplyDefaults()
		{
		}

		protected override DbCommand GetInsertCommand(CommandType commandType)
		{	
			DbCommand dbCommand;

			// Create the Database object, using the default database service. The
			// default database service is determined through configuration.
			Database db = GetDatabase();

			switch(commandType)
			{
				case CommandType.StoredProcedure:
					string sqlCommand = this.SchemaStoredProcedureWithSeparator + "sp_AddAlbumImages";
					dbCommand = db.GetStoredProcCommand(sqlCommand);

					db.AddParameter(dbCommand, "ImageID", DbType.Int32, 0, ParameterDirection.Output, true, 0, 0, "ImageID", DataRowVersion.Default, Convert.DBNull);
					CreateParameters(db, dbCommand);
					
					return dbCommand;

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					foreach(SchemaItem item in this.SchemaEntries)
					{
						if (!item.IsComputed)
						{
							if ((item.IsAutoKey && this.IdentityInsert) || !item.IsAutoKey)
							{
								this.Query.AddInsertColumn(item);
							}
						}
					}
					dbCommand = this.Query.GetInsertCommandWrapper();

					dbCommand.Parameters.Clear();
					if (this.IdentityInsert)
					{
						db.AddInParameter(dbCommand, "ImageID", DbType.Int32, "ImageID", DataRowVersion.Default);
					}
					else
					{
						db.AddParameter(dbCommand, "ImageID", DbType.Int32, 0, ParameterDirection.Output, true, 0, 0, "ImageID", DataRowVersion.Default, Convert.DBNull);
					}
					CreateParameters(db, dbCommand);

					return dbCommand;

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		protected override DbCommand GetUpdateCommand(CommandType commandType)
		{
            DbCommand dbCommand;

			// Create the Database object, using the default database service. The
			// default database service is determined through configuration.
			Database db = GetDatabase();

			switch(commandType)
			{
				case CommandType.StoredProcedure:
					string sqlCommand = this.SchemaStoredProcedureWithSeparator + "sp_UpdateAlbumImages";
					dbCommand = db.GetStoredProcCommand(sqlCommand);

					db.AddInParameter(dbCommand, "ImageID", DbType.Int32, "ImageID", DataRowVersion.Current);
					CreateParameters(db, dbCommand);
					
					return dbCommand;

				case CommandType.Text:
					this.Query.ClearAll();
					foreach(SchemaItem item in this.SchemaEntries)
					{
						if (!(item.IsAutoKey || item.IsComputed))
						{
							this.Query.AddUpdateColumn(item);
						}
					}

					this.Where.WhereClauseReset();
					this.Where.ImageID.Operator = WhereParameter.Operand.Equal;
					dbCommand = this.Query.GetUpdateCommandWrapper();

					dbCommand.Parameters.Clear();
					CreateParameters(db, dbCommand);
					db.AddInParameter(dbCommand, "ImageID", DbType.Int32, "ImageID", DataRowVersion.Current);
					
					return dbCommand;

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		protected override DbCommand GetDeleteCommand(CommandType commandType)
		{
            DbCommand dbCommand;

			// Create the Database object, using the default database service. The
			// default database service is determined through configuration.
			Database db = GetDatabase();

			switch(commandType)
			{
				case CommandType.StoredProcedure:
					string sqlCommand = this.SchemaStoredProcedureWithSeparator + "sp_DeleteAlbumImages";
					dbCommand = db.GetStoredProcCommand(sqlCommand);
					db.AddInParameter(dbCommand, "ImageID", DbType.Int32, "ImageID", DataRowVersion.Current);
					
					return dbCommand;

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					this.Where.ImageID.Operator = WhereParameter.Operand.Equal;
					dbCommand = this.Query.GetDeleteCommandWrapper();

					dbCommand.Parameters.Clear();
					db.AddInParameter(dbCommand, "ImageID", DbType.Int32, "ImageID", DataRowVersion.Current);
					
					return dbCommand;

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		private void CreateParameters(Database db, DbCommand dbCommand)
		{
			db.AddInParameter(dbCommand, "ImageName", DbType.String, "ImageName", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "AlbumID", DbType.Int32, "AlbumID", DataRowVersion.Current);
		}
		
		#region Properties
		public virtual int ImageID
		{
			get
			{
				return this.GetInteger(AlbumImagesSchema.ImageID.FieldName);
	    	}
			set
			{
				this.SetInteger(AlbumImagesSchema.ImageID.FieldName, value);
			}
		}
		public virtual string ImageName
		{
			get
			{
				return this.GetString(AlbumImagesSchema.ImageName.FieldName);
	    	}
			set
			{
				this.SetString(AlbumImagesSchema.ImageName.FieldName, value);
			}
		}
		public virtual int AlbumID
		{
			get
			{
				return this.GetInteger(AlbumImagesSchema.AlbumID.FieldName);
	    	}
			set
			{
				this.SetInteger(AlbumImagesSchema.AlbumID.FieldName, value);
			}
		}

		public override string TableName
		{
			get { return "AlbumImages"; }
		}
		
		#endregion		
		
		#region String Properties
		public virtual string s_ImageID
		{
			get
			{
			    return this.IsColumnNull(AlbumImagesSchema.ImageID.FieldName) ? string.Empty : base.GetIntegerAsString(AlbumImagesSchema.ImageID.FieldName);
			}
			set
			{
			    if(string.Empty == value)
			        this.SetColumnNull(AlbumImagesSchema.ImageID.FieldName);
			    else
			        this.ImageID = base.SetIntegerAsString(AlbumImagesSchema.ImageID.FieldName, value);
			}
		}
		public virtual string s_ImageName
		{
			get
			{
			    return this.IsColumnNull(AlbumImagesSchema.ImageName.FieldName) ? string.Empty : base.GetStringAsString(AlbumImagesSchema.ImageName.FieldName);
			}
			set
			{
			    if(string.Empty == value)
			        this.SetColumnNull(AlbumImagesSchema.ImageName.FieldName);
			    else
			        this.ImageName = base.SetStringAsString(AlbumImagesSchema.ImageName.FieldName, value);
			}
		}
		public virtual string s_AlbumID
		{
			get
			{
			    return this.IsColumnNull(AlbumImagesSchema.AlbumID.FieldName) ? string.Empty : base.GetIntegerAsString(AlbumImagesSchema.AlbumID.FieldName);
			}
			set
			{
			    if(string.Empty == value)
			        this.SetColumnNull(AlbumImagesSchema.AlbumID.FieldName);
			    else
			        this.AlbumID = base.SetIntegerAsString(AlbumImagesSchema.AlbumID.FieldName, value);
			}
		}
		#endregion		
	
		#region Where Clause
		public class WhereClause
		{
			public WhereClause(EasyObject entity)
			{
				this._entity = entity;
			}
			
			public TearOffWhereParameter TearOff
			{
				get
				{
					if(_tearOff == null)
					{
						_tearOff = new TearOffWhereParameter(this);
					}

					return _tearOff;
				}
			}

			#region TearOff's
			public class TearOffWhereParameter
			{
				public TearOffWhereParameter(WhereClause clause)
				{
					this._clause = clause;
				}
				
				
				public WhereParameter ImageID
				{
					get
					{
							WhereParameter wp = new WhereParameter(AlbumImagesSchema.ImageID);
							this._clause._entity.Query.AddWhereParameter(wp);
							return wp;
					}
				}

				public WhereParameter ImageName
				{
					get
					{
							WhereParameter wp = new WhereParameter(AlbumImagesSchema.ImageName);
							this._clause._entity.Query.AddWhereParameter(wp);
							return wp;
					}
				}

				public WhereParameter AlbumID
				{
					get
					{
							WhereParameter wp = new WhereParameter(AlbumImagesSchema.AlbumID);
							this._clause._entity.Query.AddWhereParameter(wp);
							return wp;
					}
				}


				private WhereClause _clause;
			}
			#endregion
		
			public WhereParameter ImageID
		    {
				get
		        {
					if(_ImageID_W == null)
	        	    {
						_ImageID_W = TearOff.ImageID;
					}
					return _ImageID_W;
				}
			}

			public WhereParameter ImageName
		    {
				get
		        {
					if(_ImageName_W == null)
	        	    {
						_ImageName_W = TearOff.ImageName;
					}
					return _ImageName_W;
				}
			}

			public WhereParameter AlbumID
		    {
				get
		        {
					if(_AlbumID_W == null)
	        	    {
						_AlbumID_W = TearOff.AlbumID;
					}
					return _AlbumID_W;
				}
			}

			private WhereParameter _ImageID_W = null;
			private WhereParameter _ImageName_W = null;
			private WhereParameter _AlbumID_W = null;

			public void WhereClauseReset()
			{
				_ImageID_W = null;
				_ImageName_W = null;
				_AlbumID_W = null;

				this._entity.Query.FlushWhereParameters();

			}
	
			private EasyObject _entity;
			private TearOffWhereParameter _tearOff;
			
		}
	
		public WhereClause Where
		{
			get
			{
				if(_whereClause == null)
				{
					_whereClause = new WhereClause(this);
				}
		
				return _whereClause;
			}
		}
		
		private WhereClause _whereClause = null;	
		#endregion
		
		#region Aggregate Clause
		public class AggregateClause
		{
			public AggregateClause(EasyObject entity)
			{
				this._entity = entity;
			}
			
			public TearOffAggregateParameter TearOff
			{
				get
				{
					if(_tearOff == null)
					{
						_tearOff = new TearOffAggregateParameter(this);
					}

					return _tearOff;
				}
			}

			#region TearOff's
			public class TearOffAggregateParameter
			{
				public TearOffAggregateParameter(AggregateClause clause)
				{
					this._clause = clause;
				}
				
				
				public AggregateParameter ImageID
				{
					get
					{
							AggregateParameter ap = new AggregateParameter(AlbumImagesSchema.ImageID);
							this._clause._entity.Query.AddAggregateParameter(ap);
							return ap;
					}
				}

				public AggregateParameter ImageName
				{
					get
					{
							AggregateParameter ap = new AggregateParameter(AlbumImagesSchema.ImageName);
							this._clause._entity.Query.AddAggregateParameter(ap);
							return ap;
					}
				}

				public AggregateParameter AlbumID
				{
					get
					{
							AggregateParameter ap = new AggregateParameter(AlbumImagesSchema.AlbumID);
							this._clause._entity.Query.AddAggregateParameter(ap);
							return ap;
					}
				}


				private AggregateClause _clause;
			}
			#endregion
		
			public AggregateParameter ImageID
		    {
				get
		        {
					if(_ImageID_W == null)
	        	    {
						_ImageID_W = TearOff.ImageID;
					}
					return _ImageID_W;
				}
			}

			public AggregateParameter ImageName
		    {
				get
		        {
					if(_ImageName_W == null)
	        	    {
						_ImageName_W = TearOff.ImageName;
					}
					return _ImageName_W;
				}
			}

			public AggregateParameter AlbumID
		    {
				get
		        {
					if(_AlbumID_W == null)
	        	    {
						_AlbumID_W = TearOff.AlbumID;
					}
					return _AlbumID_W;
				}
			}

			private AggregateParameter _ImageID_W = null;
			private AggregateParameter _ImageName_W = null;
			private AggregateParameter _AlbumID_W = null;

			public void AggregateClauseReset()
			{
				_ImageID_W = null;
				_ImageName_W = null;
				_AlbumID_W = null;

				this._entity.Query.FlushAggregateParameters();

			}
	
			private EasyObject _entity;
			private TearOffAggregateParameter _tearOff;
			
		}
	
		public AggregateClause Aggregate
		{
			get
			{
				if(_aggregateClause == null)
				{
					_aggregateClause = new AggregateClause(this);
				}
		
				return _aggregateClause;
			}
		}
		
		private AggregateClause _aggregateClause = null;	
		#endregion
	}
}
